#include "stdafx.h"
#include "ReadFrom.h"



Node *RekRead(TiXmlElement *el,Node* node){
	Node *tmp=NULL;
/*4.05 Pawel*/	Node *dodawany=new Node(el->Attribute("etykieta"),0,true);
	dodawany->focus=false;
/*5.05 kolaps*/	dodawany->setStrona(atoi(el->Attribute("strona")));
	node->addChild("nazwa",dodawany,false);
	tmp=node->first;
	tmp->focus=false;
	
	tmp->setXY(atoi(el->Attribute("X")),atoi(el->Attribute("Y")));
	if(atoi(el->Attribute("widoczny"))==0)
		tmp->setInvisible();
	tmp->changeColour(atoi(el->Attribute("kolor")));
	tmp->setWH(atoi(el->Attribute("szerokosc")),atoi(el->Attribute("wysokosc")));
	tmp->link=atoi(el->Attribute("link"));
	if(el->FirstChildElement()!=NULL)
	tmp=RekRead(el->FirstChildElement(),tmp);
	while(el->NextSiblingElement()!=NULL){
		el=el->NextSiblingElement();
		if(atoi(el->Attribute("strona"))==1)
/*4.05 Pawel*/		tmp->addBrother("nazwa",new Node(el->Attribute("etykieta"),0,true),false);
		else
			tmp->addBrother("nazwa",new Node(el->Attribute("etykieta"),0,false),false);

		tmp=tmp->next;
		tmp->focus=false;
		
		tmp->setXY(atoi(el->Attribute("X")),atoi(el->Attribute("Y")));
			if(atoi(el->Attribute("widoczny"))==0)
			tmp->setInvisible();
		tmp->changeColour(atoi(el->Attribute("kolor")));
		tmp->setWH(atoi(el->Attribute("szerokosc")),atoi(el->Attribute("wysokosc")));
		tmp->link=atoi(el->Attribute("link"));
		if(el->FirstChildElement()!=NULL)
		tmp=RekRead(el->FirstChildElement(),tmp);
		
	}
	node->focus=0;
	return node;
};






Root *ReadFrom(char* sciezka,Root* tree){
	
	Root *tmp=new Root("Map1",500,350,0);
	TiXmlDocument doc;
	bool LoadOkay=doc.LoadFile(sciezka);
	if(LoadOkay==false){
		return tree;
	}
	TiXmlElement *el=doc.RootElement();
	tmp->NodeName=el->Attribute("etykieta");
	
	tmp->setXY(atoi(el->Attribute("X")),atoi(el->Attribute("Y")));
	if(atoi(el->Attribute("widoczny"))==0)
			tmp->setInvisible();
	tmp->changeColour(atoi(el->Attribute("kolor")));
	tmp->setWH(atoi(el->Attribute("szerokosc")),atoi(el->Attribute("wysokosc")));
	tmp->link=atoi(el->Attribute("link"));
	if(el->FirstChildElement()!=NULL)
		tmp=(Root*)RekRead(el->FirstChildElement(),(Node*) tmp);	
	tmp->focus=0;

	return tmp;
}